package com.supermap.hn.traffic.config;


import com.supermap.hn.traffic.helper.XMLHelper;
import lombok.Getter;
import lombok.Setter;

import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.w3c.dom.Element;

@Component
@Getter
@Setter
public class NetworkConfig {

    /**
     * 工作空间路径
     */
    private String workspacePath;

    /**
     * 数据源名称
     */
    private String datasourceName;
    /**
     * 结果数据源名称
     */
    private  String resdatasourceName;
    /**
     * 数据集名称
     */
    private String datasetName;

    /**
     * 货车/卡车特殊限速数据集名称
     */
    private String HdatasetName;

    /**
     * 小车/客车特殊限速数据集名称
     */
    private String KdatasetName;

    /**
     * 范围数据集名称
     */
    private String regionDatasetName;

    /**
     * 路网节点ID字段
     */
    private String nodeIDField;

    /**
     * 路网弧段ID字段
     */
    private String edgeIDField;

    /**
     * 路网弧段名称字段
     */
    private String edgeNameField;

    /**
     * 路网弧段起点ID字段
     */
    private String FNodeIDField;

    /**
     * 路网弧段终点ID字段
     */
    private String TNodeIDField;

    /**
     * 权重信息名称
     */
    private String weightName;

    /**
     * 正向阻力字段
     */
    private String FTWeightField;

    /**
     * 逆向阻力字段
     */
    private String TFWeightField;

    /**
     * 轨迹点误差值
     */
    private double measurementError;

    /**
     * 最大限制速度
     */
    private double maxLimitedSpeed;

    /**
     * 上行速度字段
     */
    private String upLimitedSpeedField;

    /**
     * 下行速度字段
     */
    private String downLimitedSpeedField;

    /**
     * 限速
     */
    private String speedLimit;

    /**
     * 特殊限速条件
     */
    private String Dependent;

    /**
     * SSC文件路径
     */
    private String sscFilePath;

    /**
     * 道路等级字段
     */
    private String levelField;

    public NetworkConfig(Environment env) throws Exception {
        String path = env.getProperty("configpath");
        //获取xml根元素
        Element root = XMLHelper.getRootElementFromPath(path);
        this.workspacePath = XMLHelper.getElementByName(root, "workspacePath");
        this.datasourceName = XMLHelper.getElementByName(root, "datasourceName");
        this.resdatasourceName = XMLHelper.getElementByName(root, "resdatasourceName");
        this.datasetName = XMLHelper.getElementByName(root, "datasetName");
        this.HdatasetName = XMLHelper.getElementByName(root, "HdatasetName");
        this.KdatasetName = XMLHelper.getElementByName(root, "KdatasetName");
        this.regionDatasetName = XMLHelper.getElementByName(root, "regionDatasetName");
        this.nodeIDField = XMLHelper.getElementByName(root, "nodeIDField");
        this.edgeIDField = XMLHelper.getElementByName(root, "edgeIDField");
        this.edgeNameField = XMLHelper.getElementByName(root, "edgeNameField");
        this.FNodeIDField = XMLHelper.getElementByName(root, "FNodeIDField");
        this.TNodeIDField = XMLHelper.getElementByName(root, "TNodeIDField");
        this.weightName = XMLHelper.getElementByName(root, "weightName");
        this.FTWeightField = XMLHelper.getElementByName(root, "FTWeightField");
        this.TFWeightField = XMLHelper.getElementByName(root, "TFWeightField");
        this.measurementError = Double.parseDouble(XMLHelper.getElementByName(root, "measurementError"));
        this.maxLimitedSpeed = Double.parseDouble(XMLHelper.getElementByName(root, "maxLimitedSpeed"));
        this.upLimitedSpeedField = XMLHelper.getElementByName(root, "upLimitedSpeedField");
        this.downLimitedSpeedField = XMLHelper.getElementByName(root, "downLimitedSpeedField");
        this.speedLimit = XMLHelper.getElementByName(root, "speedLimit");
        this.Dependent = XMLHelper.getElementByName(root, "SpecialLimitDependent");
        this.levelField = XMLHelper.getElementByName(root, "levelField");
        this.sscFilePath = XMLHelper.getElementByName(root, "sscFilePath");

    }
}
